package com.easyctrl.adapter;

import java.util.ArrayList;
 
import com.easyctrl.ldy.activity.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class LampDeviceAdapter extends BaseAdapter {
	private static LampDeviceAdapter instance;
	private ArrayList<String> contents;
	private LayoutInflater mInflater;
	private LampDeviceAdapter(Context context,ArrayList<String> contents){
		this.contents = contents;
		mInflater = LayoutInflater.from(context);
	}
	
	public static LampDeviceAdapter getInstance(Context context,ArrayList<String> contents){
		if(instance == null){
			instance = new LampDeviceAdapter(context, contents);
		}
		return instance;
	}
	
	@Override
	public int getCount() { 
		return contents == null ? 0 : contents.size();
	}

	@Override
	public Object getItem(int position) { 
		return contents.get(position);
	}

	@Override
	public long getItemId(int id) { 
		return 0;
	}

	@Override
	public View getView(int position, View contentView, ViewGroup parent) { 
		String content = contents.get(position);
		ViewHoleder holder = null;
		if(contentView == null){
			holder = new ViewHoleder();
			contentView = mInflater.inflate(R.layout.select_string_dialog_item, parent,false);
			holder.text = (TextView) contentView.findViewById(R.id.textname);
			contentView.setTag(holder);
		}else{
			holder = (ViewHoleder) contentView.getTag();
		}
		holder.text.setText(content);
		return contentView;
	}
	
	public class ViewHoleder {
		public TextView text;
	}

	public void setContents(ArrayList<String> contents) {
		this.contents = contents;
	} 
}
